Miles Sound System SDK 7.2a

Callbacks under Xbox

Discussion

Read this section carefully if you plan to use Miles timer or other callbacks (such as an end-of-sample callback). If you don't intend to use callbacks, then this section won't apply to you.

On the Xbox, callbacks are usually made to your application on a background thread. The ideal callback function is one that does nothing more than write to one or two flag variables and then immediately return back to Miles. On Xbox, other operations are allowed, but not recommended!

So, unlike MacOS 9 or PS2, you can do whatever you want inside a Miles callback on the Xbox - there are no OS-mandated restrictions. However, if you want to maintain easily ported code, then you should read about the callback restrictions for the other platforms you intend to support. Other platforms are much more strict than Xbox when it comes to callbacks.

In any case, you do have to take general multithread precautions in your callbacks. For example, if you use the C runtime library inside a callback, then you need to link with the multithreaded libraries. If you access your own internal data structures, then you need to make sure that the accessor functions can be called by two threads at once (unless you protect with a critical section lock).

Also remember that all global or static variables that are modified by a callback function must be declared with the volatile modifier. Otherwise, the callback function and the foreground may not be able to communicate after the compiler has performed all of its optimizing tricks.

You should also minimize the total amount of work inside a Miles callback. During a callback, Miles is suspended, so other background tasks won't run - mixing will be interrupted, for example, if you take too long.

Again, though, the best advice for callbacks is to simply post a message or set a flag that can be operated on by your foreground task. This technique works on all platforms and you'll never need to worry about the complications that multithreading can cause.

Next Topic (Sharing the CPU under Xbox)

Previous Topic (Memory management under Xbox)


Group: Overview for Microsoft Xbox

For technical support, e-mail Miles3@radgametools.com
© Copyright 1991-2007 RAD Game Tools, Inc. All Rights Reserved.